Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build only lib from package #839

Merged
merged 1 commit into from
Nov 14, 2014
Merged

Build only lib from package #839

merged 1 commit into from
Nov 14, 2014

Conversation

vhbit
Copy link
Contributor

@vhbit vhbit commented Nov 11, 2014

Fixes #724

@vhbit
Copy link
Contributor Author

vhbit commented Nov 11, 2014

@alexcrichton r?

@alexcrichton
Copy link
Member

I think the plan was to add --name to the list of arguments to cargo build to stay in line with the rest of the cargo commands. I'd also be fine adding logic that just doesn't built executables for platforms that don't support executables instead of adding another flag.

@stepancheg stepancheg mentioned this pull request Nov 11, 2014
@vhbit
Copy link
Contributor Author

vhbit commented Nov 12, 2014

@alexcrichton hmm, my motivation was:

  • so far there could be only one library in the package so it is natural to skip its name as it is inferred
  • providing a name for build actually should also take into account that build is general and might be used for all kind of binaries (cargo build --bins #843 is about it).

So if sticking with the --name plan perhaps a better alternative is to provide type of build like: cargo build --name foo:lib or cargo build --name foo:bin --name foo:test --name foo:example. In this case --name could be skipped at all. But I'm not sure this actually is that much needed as plain lib.

I'd also be fine adding logic that just doesn't built executables for platforms that don't support executables instead of adding another flag.

It is not just about platform support - it also might speed up compilation when all you need is the library itself.

@alexcrichton
Copy link
Member

Ok thinking about this, I think this may be the best way to go. The reason I didn't like --test foo for cargo test was that you stuttered with cargo test --test foo and there is only one type of target to run there (test targets!), so specifying --test seemed redundant.

Here though I don't think it's worth it to implement --name due to clashes. Requiring foo:lib means that it's somewhat counterintuitive, and implementing a system which accepts cargo build --name foo and succeeds with one target named foo and fails with more than one target named foo also seems overly complicated.

In the end I think that --lib and --bins are kinda the most expected of the bunch. This does, however lend to a bit of a clash between cargo build and the other commands which all accept --name across the board. I'm somewhat uneasy with that, but I could also live with it in the end.

I'll consult with a few others about this tomorrow and get back to you about what we think the best way to go about this is. Also cc @stepancheg, this is basically the same outcome for #843 I believe.

@vhbit
Copy link
Contributor Author

vhbit commented Nov 13, 2014

hmm, any ideas why it fails cross compile tests on OS X and if it is really related to this patch (it seems to be an error with lib paths as it can't find std crate)?

@alexcrichton
Copy link
Member

Ah it's ok, it looks like the download of the nightly failed which was probably spurious

@alexcrichton
Copy link
Member

@vhbit, @stepancheg, alright, let's move forward with these PRs. I'll rename --name to --target-name for the other commands soon.


assert_that(p.cargo_process("build").arg("--lib"),
execs().with_status(0));
assert_that(&p.bin("foo"), is_not(existing_file()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test against the output with -v to ensure that the library actually was built?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, isn't it enough just to test if lib file exists?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that'd also work.

alexcrichton added a commit to alexcrichton/cargo that referenced this pull request Nov 13, 2014
With rust-lang#843 and rust-lang#839 coming around the bend soon, the original decision for
`--name` everywhere isn't making as much sense, for consistence this is renaming
these flags back to `--<target-name>` for the respective targets.
@vhbit
Copy link
Contributor Author

vhbit commented Nov 14, 2014

Added error if no libs are presented, added a test case for it, also while building just lib checking verbose output.

@@ -27,6 +27,7 @@ macro_rules! test(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this file turned into an executable, could you flip it back?

@alexcrichton
Copy link
Member

Looks great, thanks @vhbit!

@vhbit
Copy link
Contributor Author

vhbit commented Nov 14, 2014

Ahh, that strange problem with emacs sometimes changing permissions only for .rs... Can't find the reason.

Anyway, fixed.

bors added a commit that referenced this pull request Nov 14, 2014
@bors bors merged commit 9c1c363 into rust-lang:master Nov 14, 2014
bors added a commit that referenced this pull request Nov 14, 2014
With #843 and #839 coming around the bend soon, the original decision for
`--name` everywhere isn't making as much sense, for consistence this is renaming
these flags back to `--<target-name>` for the respective targets.
}).filter(|target| !lib_only || target.is_lib()).collect::<Vec<&Target>>();

if lib_only && targets.len() == 0 {
return Err(human("There is no lib to build, remove `--lib` flag".to_string()));
Copy link

@ryoqun ryoqun Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to build only lib
4 participants